﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 9/1/2009
 * Time: 11:57 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Buaya.Model;

namespace Buaya.Gui
{
	/// <summary>
	/// Description of PayrollCodeForm.
	/// </summary>
	public partial class PayrollCodeForm : BaseForm
	{
		public PayrollCodeForm() : this(new PayrollCode())
		{
			
		}
		
		public PayrollCodeForm(PayrollCode c)
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			Model = c;
		}
		
		protected override void OnModelChanged(EventArgs e)
		{
			base.OnModelChanged(e);
			PayrollCode c = Model as PayrollCode;
			textBoxCode.Text = c.Code;
			dateTimePickerStart.Value = c.StartDate;
			dateTimePickerEnd.Value = c.EndDate;
			checkBoxDeductSSSPremium.Checked = c.DeductSSPremium;
			checkBoxDeductPagIbigPremium.Checked = c.DeductPagIBIGPremium;
			checkBoxDeductPhilhealthPremium.Checked = c.DeductPhilhealthPremium;
			checkBoxDeductWithholdingTax.Checked = c.DeductWithholdingTax;
			textBoxOTRegularRate.Text = c.OTRegularRate.ToString("0.00");
			textBoxOTSundayRate.Text = c.OTSundayRate.ToString("0.00");
			textBoxOTLegalRate.Text = c.OTLegalRate.ToString("0.00");
			textBoxOTSpecialRate.Text = c.OTSpecialRate.ToString("0.00");
			textBoxOTLegalSunday.Text = c.OTLegalSundayRate.ToString("0.00");
			checkBoxInactive.Checked = c.Inactive;
		}
		
		void ButtonOkClick(object sender, EventArgs e)
		{
			PayrollCode c = Model as PayrollCode;
			c.Code = textBoxCode.Text;
			c.StartDate = dateTimePickerStart.Value;
			c.EndDate = dateTimePickerEnd.Value;
			c.DeductSSPremium = checkBoxDeductSSSPremium.Checked;
			c.DeductPagIBIGPremium = checkBoxDeductPagIbigPremium.Checked;
			c.DeductPhilhealthPremium = checkBoxDeductPhilhealthPremium.Checked;
			c.DeductWithholdingTax = checkBoxDeductWithholdingTax.Checked;
			c.OTRegularRate = Util.ConvertUtility.ToDouble(textBoxOTRegularRate.Text);
			c.OTSundayRate = Util.ConvertUtility.ToDouble(textBoxOTSundayRate.Text);
			c.OTLegalRate = Util.ConvertUtility.ToDouble(textBoxOTLegalRate.Text);
			c.OTSpecialRate = Util.ConvertUtility.ToDouble(textBoxOTSpecialRate.Text);
			c.OTLegalSundayRate = Util.ConvertUtility.ToDouble(textBoxOTLegalSunday.Text);
			c.Inactive = checkBoxInactive.Checked;
			SessionFacade.SaveOrUpdatePayrollCode(c);
			Close();
		}
		
		void ButtonCancelClick(object sender, EventArgs e)
		{
			Close();
		}
	}
}
